<template><div><p>本文档最新版为 <a href="https://learnku.com/docs/laravel/10.x" target="_blank" rel="noopener noreferrer">10.x</a>，旧版本可能放弃维护，推荐阅读最新版！</p>
<h2 id="laravel-telescope" tabindex="-1"><a class="header-anchor" href="#laravel-telescope"><span>Laravel Telescope</span></a></h2>
<ul>
<li><a href="#introduction">简介</a></li>
<li><a href="#installation">安装</a>
<ul>
<li><a href="#configuration">配置</a></li>
<li><a href="#data-pruning">数据修改</a></li>
<li><a href="#migration-customization">数据迁移</a></li>
</ul>
</li>
<li><a href="#dashboard-authorization">仪表板授权</a></li>
<li><a href="#filtering">过滤</a>
<ul>
<li><a href="#filtering-entries">单项过滤</a></li>
<li><a href="#filtering-batches">批量过滤</a></li>
</ul>
</li>
<li><a href="#tagging">标记</a></li>
<li><a href="#available-watchers">可用的监听</a>
<ul>
<li><a href="#cache-watcher">缓存监听</a></li>
<li><a href="#command-watcher">命令监听</a></li>
<li><a href="#dump-watcher">储存监听</a></li>
<li><a href="#event-watcher">事件监听</a></li>
<li><a href="#exception-watcher">异常监听</a></li>
<li><a href="#gate-watcher">Gate 监听</a></li>
<li><a href="#job-watcher">进程监听</a></li>
<li><a href="#log-watcher">日志监听</a></li>
<li><a href="#mail-watcher">邮件监听</a></li>
<li><a href="#model-watcher">模型监听</a></li>
<li><a href="#notification-watcher">消息通知监听</a></li>
<li><a href="#query-watcher">数据查询监听</a></li>
<li><a href="#redis-watcher">Redis 监听</a></li>
<li><a href="#request-watcher">请求监听</a></li>
<li><a href="#schedule-watcher">定时任务监听</a></li>
</ul>
</li>
</ul>
<h2 id="简介" tabindex="-1"><a class="header-anchor" href="#简介"><span>简介</span></a></h2>
<p>Larave Telescope 是 Laravel 框架的优雅调试助手。Telescope 可深入了解进入应用程序的请求、异常、日志条目、数据库查询、排队作业、邮件、通知、缓存操作、计划任务、变量转储等。Telescope 是您本地 Laravel 开发环境的绝佳伴侣。</p>
<p><img src="https://cdn.learnku.com/uploads/images/201904/22/29333/Brtb1DNyg7.png!large" alt="Brtb1DNyg7.png!large"></p>
<h2 id="安装" tabindex="-1"><a class="header-anchor" href="#安装"><span>安装</span></a></h2>
<p>你可以使用 Composer 在 Laravel 项目中安装 Telescope 扩展：</p>
<div class="language-php line-numbers-mode" data-highlighter="prismjs" data-ext="php" data-title="php"><pre v-pre class="language-php"><code><span class="line">composer <span class="token keyword">require</span> laravel<span class="token operator">/</span>telescope<span class="token punctuation">:</span><span class="token operator">^</span><span class="token number">3.0</span></span>
<span class="line"></span></code></pre>
<div class="line-numbers" aria-hidden="true" style="counter-reset:line-number 0"><div class="line-number"></div></div></div><p>安装 Telescope 后，可以在 Artisan 使用 <code v-pre>telescope:install</code> 命令来配置扩展实例。安装 Telescope 后，还应运行 <code v-pre>migrate</code> 命令：</p>
<div class="language-php line-numbers-mode" data-highlighter="prismjs" data-ext="php" data-title="php"><pre v-pre class="language-php"><code><span class="line">php artisan telescope<span class="token punctuation">:</span>install</span>
<span class="line"></span>
<span class="line">php artisan migrate</span>
<span class="line"></span></code></pre>
<div class="line-numbers" aria-hidden="true" style="counter-reset:line-number 0"><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div></div></div><h4 id="更新-telescope" tabindex="-1"><a class="header-anchor" href="#更新-telescope"><span>更新 Telescope</span></a></h4>
<p>更新 Telescope 时，您应该重新配置加载 Telescope 实例：</p>
<div class="language-php line-numbers-mode" data-highlighter="prismjs" data-ext="php" data-title="php"><pre v-pre class="language-php"><code><span class="line">php artisan telescope<span class="token punctuation">:</span>publish</span>
<span class="line"></span></code></pre>
<div class="line-numbers" aria-hidden="true" style="counter-reset:line-number 0"><div class="line-number"></div></div></div><h3 id="仅在特定环境中安装" tabindex="-1"><a class="header-anchor" href="#仅在特定环境中安装"><span>仅在特定环境中安装</span></a></h3>
<p>如果您打算仅使用 Telescope 来协助您的本地开发。可以使用 <code v-pre>--dev</code> 标志安装 Telescope：</p>
<div class="language-php line-numbers-mode" data-highlighter="prismjs" data-ext="php" data-title="php"><pre v-pre class="language-php"><code><span class="line">composer <span class="token keyword">require</span> laravel<span class="token operator">/</span>telescope <span class="token operator">--</span>dev</span>
<span class="line"></span></code></pre>
<div class="line-numbers" aria-hidden="true" style="counter-reset:line-number 0"><div class="line-number"></div></div></div><p>运行 <code v-pre>telescope:install</code> 后，您应该从 <code v-pre>app</code> 配置文件中删除 <code v-pre>TelescopeServiceProvider</code> 服务提供注册。相反，在 <code v-pre>AppServiceProvider</code> 的 <code v-pre>register</code> 方法中手动注册服务：</p>
<div class="language-php line-numbers-mode" data-highlighter="prismjs" data-ext="php" data-title="php"><pre v-pre class="language-php"><code><span class="line"><span class="token doc-comment comment">/**</span>
<span class="line"> * 注册应用服务。</span>
<span class="line"> *</span>
<span class="line"> * <span class="token keyword">@return</span> <span class="token class-name"><span class="token keyword">void</span></span></span>
<span class="line"> */</span></span>
<span class="line"><span class="token keyword">public</span> <span class="token keyword">function</span> <span class="token function-definition function">register</span><span class="token punctuation">(</span><span class="token punctuation">)</span></span>
<span class="line"><span class="token punctuation">{</span></span>
<span class="line">    <span class="token keyword">if</span> <span class="token punctuation">(</span><span class="token variable">$this</span><span class="token operator">-></span><span class="token property">app</span><span class="token operator">-></span><span class="token function">isLocal</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">)</span> <span class="token punctuation">{</span></span>
<span class="line">        <span class="token variable">$this</span><span class="token operator">-></span><span class="token property">app</span><span class="token operator">-></span><span class="token function">register</span><span class="token punctuation">(</span><span class="token class-name static-context">TelescopeServiceProvider</span><span class="token operator">::</span><span class="token keyword">class</span><span class="token punctuation">)</span><span class="token punctuation">;</span></span>
<span class="line">    <span class="token punctuation">}</span></span>
<span class="line"><span class="token punctuation">}</span></span>
<span class="line"></span></code></pre>
<div class="line-numbers" aria-hidden="true" style="counter-reset:line-number 0"><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div></div></div><h3 id="定制数据迁移" tabindex="-1"><a class="header-anchor" href="#定制数据迁移"><span>定制数据迁移</span></a></h3>
<p>如果您不打算使用 Telescope 的默认迁移，则应该在 <code v-pre>AppServiceProvider</code> 的 <code v-pre>register</code> 方法中调用 <code v-pre>Telescope::ignoreMigrations</code> 方法。您可以使用 <code v-pre>php artisan vendor:publish --tag=telescope-migrations</code>命令导出默认迁移。</p>
<h3 id="配置" tabindex="-1"><a class="header-anchor" href="#配置"><span>配置</span></a></h3>
<p>使用 Telescope，其主要配置文件将位于 <code v-pre>config/telescope.php</code>。此配置文件允许您配置监听程序选项，每个配置选项都包含其用途说明，因此请务必彻底浏览此文件。</p>
<p>如果需要，您可以使用 <code v-pre>enabled</code> 配置选项完全禁用 Telescope 的数据收集：</p>
<div class="language-php line-numbers-mode" data-highlighter="prismjs" data-ext="php" data-title="php"><pre v-pre class="language-php"><code><span class="line"><span class="token string single-quoted-string">'enabled'</span> <span class="token operator">=></span> <span class="token function">env</span><span class="token punctuation">(</span><span class="token string single-quoted-string">'TELESCOPE_ENABLED'</span><span class="token punctuation">,</span> <span class="token constant boolean">true</span><span class="token punctuation">)</span><span class="token punctuation">,</span></span>
<span class="line"></span></code></pre>
<div class="line-numbers" aria-hidden="true" style="counter-reset:line-number 0"><div class="line-number"></div></div></div><h3 id="数据修改" tabindex="-1"><a class="header-anchor" href="#数据修改"><span>数据修改</span></a></h3>
<p>有了数据修改，<code v-pre>telescope_entries</code> 表可以非常快速地累积记录。为了缓解这个问题，你应该使用 Artisan 每天运行 <code v-pre>telescope:prune</code> 命令：</p>
<div class="language-php line-numbers-mode" data-highlighter="prismjs" data-ext="php" data-title="php"><pre v-pre class="language-php"><code><span class="line"><span class="token variable">$schedule</span><span class="token operator">-></span><span class="token function">command</span><span class="token punctuation">(</span><span class="token string single-quoted-string">'telescope:prune'</span><span class="token punctuation">)</span><span class="token operator">-></span><span class="token function">daily</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span></span>
<span class="line"></span></code></pre>
<div class="line-numbers" aria-hidden="true" style="counter-reset:line-number 0"><div class="line-number"></div></div></div><p>默认情况下，将获取超过 24 小时的所有数据。在调用命令时可以使用 <code v-pre>hours</code> 选项来确定保留 Telescope 数据的时间。例如，以下命令将删除 48 小时前创建的所有记录：</p>
<div class="language-php line-numbers-mode" data-highlighter="prismjs" data-ext="php" data-title="php"><pre v-pre class="language-php"><code><span class="line"><span class="token variable">$schedule</span><span class="token operator">-></span><span class="token function">command</span><span class="token punctuation">(</span><span class="token string single-quoted-string">'telescope:prune --hours=48'</span><span class="token punctuation">)</span><span class="token operator">-></span><span class="token function">daily</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span></span>
<span class="line"></span></code></pre>
<div class="line-numbers" aria-hidden="true" style="counter-reset:line-number 0"><div class="line-number"></div></div></div><h2 id="仪表板授权" tabindex="-1"><a class="header-anchor" href="#仪表板授权"><span>仪表板授权</span></a></h2>
<p>Telescope 在 <code v-pre>/telescope</code> 处显示仪表板。默认情况下，您只能在 <code v-pre>本地</code> 环境中访问此仪表板。在你的 <code v-pre>app/Providers/TelescopeServiceProvider.php</code> 文件中，有一个 <code v-pre>gate</code> 方法。此授权能控制在 <strong>非本地</strong> 环境中对 Telescope 的访问。您可以根据需要随意修改此权限限制以对 Telescope 安装和访问：</p>
<div class="language-php line-numbers-mode" data-highlighter="prismjs" data-ext="php" data-title="php"><pre v-pre class="language-php"><code><span class="line"><span class="token doc-comment comment">/**</span>
<span class="line"> * 注册 Telescope gate.</span>
<span class="line"> *</span>
<span class="line"> * 使用 Gate 决定谁可以在非本地环境中访问 Telescope。</span>
<span class="line"> *</span>
<span class="line"> * <span class="token keyword">@return</span> <span class="token class-name"><span class="token keyword">void</span></span></span>
<span class="line"> */</span></span>
<span class="line"><span class="token keyword">protected</span> <span class="token keyword">function</span> <span class="token function-definition function">gate</span><span class="token punctuation">(</span><span class="token punctuation">)</span></span>
<span class="line"><span class="token punctuation">{</span></span>
<span class="line">    <span class="token class-name static-context">Gate</span><span class="token operator">::</span><span class="token function">define</span><span class="token punctuation">(</span><span class="token string single-quoted-string">'viewTelescope'</span><span class="token punctuation">,</span> <span class="token keyword">function</span> <span class="token punctuation">(</span><span class="token variable">$user</span><span class="token punctuation">)</span> <span class="token punctuation">{</span></span>
<span class="line">        <span class="token keyword">return</span> <span class="token function">in_array</span><span class="token punctuation">(</span><span class="token variable">$user</span><span class="token operator">-></span><span class="token property">email</span><span class="token punctuation">,</span> <span class="token punctuation">[</span></span>
<span class="line">            <span class="token string single-quoted-string">'taylor@laravel.com'</span><span class="token punctuation">,</span></span>
<span class="line">        <span class="token punctuation">]</span><span class="token punctuation">)</span><span class="token punctuation">;</span></span>
<span class="line">    <span class="token punctuation">}</span><span class="token punctuation">)</span><span class="token punctuation">;</span></span>
<span class="line"><span class="token punctuation">}</span></span>
<span class="line"></span></code></pre>
<div class="line-numbers" aria-hidden="true" style="counter-reset:line-number 0"><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div></div></div><h2 id="过滤" tabindex="-1"><a class="header-anchor" href="#过滤"><span>过滤</span></a></h2>
<h3 id="单项过滤" tabindex="-1"><a class="header-anchor" href="#单项过滤"><span>单项过滤</span></a></h3>
<p>您可以通过在 <code v-pre>TelescopeServiceProvider</code> 中注册的 <code v-pre>filter</code> 回调来过滤 Telescope 记录的数据。默认情况下，此回调会记录 <code v-pre>本地</code> 环境中的所有数据以及所有其他环境中的异常、进程中断、计划任务和带有受监控标记的数据：</p>
<div class="language-php line-numbers-mode" data-highlighter="prismjs" data-ext="php" data-title="php"><pre v-pre class="language-php"><code><span class="line"><span class="token doc-comment comment">/**</span>
<span class="line"> * 注册应用服务</span>
<span class="line"> *</span>
<span class="line"> * <span class="token keyword">@return</span> <span class="token class-name"><span class="token keyword">void</span></span></span>
<span class="line"> */</span></span>
<span class="line"><span class="token keyword">public</span> <span class="token keyword">function</span> <span class="token function-definition function">register</span><span class="token punctuation">(</span><span class="token punctuation">)</span></span>
<span class="line"><span class="token punctuation">{</span></span>
<span class="line">    <span class="token variable">$this</span><span class="token operator">-></span><span class="token function">hideSensitiveRequestDetails</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span></span>
<span class="line"></span>
<span class="line">    <span class="token class-name static-context">Telescope</span><span class="token operator">::</span><span class="token function">filter</span><span class="token punctuation">(</span><span class="token keyword">function</span> <span class="token punctuation">(</span><span class="token class-name type-declaration">IncomingEntry</span> <span class="token variable">$entry</span><span class="token punctuation">)</span> <span class="token punctuation">{</span></span>
<span class="line">        <span class="token keyword">if</span> <span class="token punctuation">(</span><span class="token variable">$this</span><span class="token operator">-></span><span class="token property">app</span><span class="token operator">-></span><span class="token function">isLocal</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">)</span> <span class="token punctuation">{</span></span>
<span class="line">            <span class="token keyword">return</span> <span class="token constant boolean">true</span><span class="token punctuation">;</span></span>
<span class="line">        <span class="token punctuation">}</span></span>
<span class="line"></span>
<span class="line">        <span class="token keyword">return</span> <span class="token variable">$entry</span><span class="token operator">-></span><span class="token function">isReportableException</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token operator">||</span></span>
<span class="line">            <span class="token variable">$entry</span><span class="token operator">-></span><span class="token function">isFailedJob</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token operator">||</span></span>
<span class="line">            <span class="token variable">$entry</span><span class="token operator">-></span><span class="token function">isScheduledTask</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token operator">||</span></span>
<span class="line">            <span class="token variable">$entry</span><span class="token operator">-></span><span class="token function">hasMonitoredTag</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span></span>
<span class="line">    <span class="token punctuation">}</span><span class="token punctuation">)</span><span class="token punctuation">;</span></span>
<span class="line"><span class="token punctuation">}</span></span>
<span class="line"></span></code></pre>
<div class="line-numbers" aria-hidden="true" style="counter-reset:line-number 0"><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div></div></div><h3 id="批量过滤" tabindex="-1"><a class="header-anchor" href="#批量过滤"><span>批量过滤</span></a></h3>
<p>虽然 <code v-pre>filter</code> 回调过滤单个条目的数据，但您可以使用 <code v-pre>filterBatch</code> 方法注册一个回调，该回调过滤给定请求或控制台命令的所有数据。如果回调返回 <code v-pre>true</code> ，则所有数据都由 Telescope 记录：</p>
<div class="language-php line-numbers-mode" data-highlighter="prismjs" data-ext="php" data-title="php"><pre v-pre class="language-php"><code><span class="line"><span class="token keyword">use</span> <span class="token package">Illuminate<span class="token punctuation">\</span>Support<span class="token punctuation">\</span>Collection</span><span class="token punctuation">;</span></span>
<span class="line"></span>
<span class="line"><span class="token doc-comment comment">/**</span>
<span class="line"> * 注册应用服务</span>
<span class="line"> *</span>
<span class="line"> * <span class="token keyword">@return</span> <span class="token class-name"><span class="token keyword">void</span></span></span>
<span class="line"> */</span></span>
<span class="line"><span class="token keyword">public</span> <span class="token keyword">function</span> <span class="token function-definition function">register</span><span class="token punctuation">(</span><span class="token punctuation">)</span></span>
<span class="line"><span class="token punctuation">{</span></span>
<span class="line">    <span class="token variable">$this</span><span class="token operator">-></span><span class="token function">hideSensitiveRequestDetails</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span></span>
<span class="line"></span>
<span class="line">    <span class="token class-name static-context">Telescope</span><span class="token operator">::</span><span class="token function">filterBatch</span><span class="token punctuation">(</span><span class="token keyword">function</span> <span class="token punctuation">(</span><span class="token class-name type-declaration">Collection</span> <span class="token variable">$entries</span><span class="token punctuation">)</span> <span class="token punctuation">{</span></span>
<span class="line">        <span class="token keyword">if</span> <span class="token punctuation">(</span><span class="token variable">$this</span><span class="token operator">-></span><span class="token property">app</span><span class="token operator">-></span><span class="token function">isLocal</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">)</span> <span class="token punctuation">{</span></span>
<span class="line">            <span class="token keyword">return</span> <span class="token constant boolean">true</span><span class="token punctuation">;</span></span>
<span class="line">        <span class="token punctuation">}</span></span>
<span class="line"></span>
<span class="line">        <span class="token keyword">return</span> <span class="token variable">$entries</span><span class="token operator">-></span><span class="token function">contains</span><span class="token punctuation">(</span><span class="token keyword">function</span> <span class="token punctuation">(</span><span class="token variable">$entry</span><span class="token punctuation">)</span> <span class="token punctuation">{</span></span>
<span class="line">            <span class="token keyword">return</span> <span class="token variable">$entry</span><span class="token operator">-></span><span class="token function">isReportableException</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token operator">||</span></span>
<span class="line">                <span class="token variable">$entry</span><span class="token operator">-></span><span class="token function">isFailedJob</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token operator">||</span></span>
<span class="line">                <span class="token variable">$entry</span><span class="token operator">-></span><span class="token function">isScheduledTask</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token operator">||</span></span>
<span class="line">                <span class="token variable">$entry</span><span class="token operator">-></span><span class="token function">hasMonitoredTag</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span></span>
<span class="line">            <span class="token punctuation">}</span><span class="token punctuation">)</span><span class="token punctuation">;</span></span>
<span class="line">    <span class="token punctuation">}</span><span class="token punctuation">)</span><span class="token punctuation">;</span></span>
<span class="line"><span class="token punctuation">}</span></span>
<span class="line"></span></code></pre>
<div class="line-numbers" aria-hidden="true" style="counter-reset:line-number 0"><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div></div></div><h2 id="标签" tabindex="-1"><a class="header-anchor" href="#标签"><span>标签</span></a></h2>
<p><code v-pre>Telescope</code> 允许你通过 <code v-pre>tag</code> 搜索条目。通常，标签是 <code v-pre>Eloquent</code> 的模型类名或经过身份验证的用户id，这些标签会自动添加到条目中。有时，您可能希望将自己的自定义标签附加到条目中。你可以使用 <code v-pre>telescope::tag</code> 方法。 <code v-pre>tag</code> 方法接受一个回调，该回调应返回一个标签数组。回调返回的标签将与 <code v-pre>telescope</code> 自动附加到条目的任何标签合并。您应该在<code v-pre>TelescopeServiceProvider</code> 中调用<code v-pre>tag</code>方法:</p>
<div class="language-php line-numbers-mode" data-highlighter="prismjs" data-ext="php" data-title="php"><pre v-pre class="language-php"><code><span class="line"><span class="token keyword">use</span> <span class="token package">Laravel<span class="token punctuation">\</span>Telescope<span class="token punctuation">\</span>Telescope</span><span class="token punctuation">;</span></span>
<span class="line"></span>
<span class="line"><span class="token doc-comment comment">/**</span>
<span class="line"> * 注册应用服务</span>
<span class="line"> *</span>
<span class="line"> * <span class="token keyword">@return</span> <span class="token class-name"><span class="token keyword">void</span></span></span>
<span class="line"> */</span></span>
<span class="line"><span class="token keyword">public</span> <span class="token keyword">function</span> <span class="token function-definition function">register</span><span class="token punctuation">(</span><span class="token punctuation">)</span></span>
<span class="line"><span class="token punctuation">{</span></span>
<span class="line">    <span class="token variable">$this</span><span class="token operator">-></span><span class="token function">hideSensitiveRequestDetails</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span></span>
<span class="line"></span>
<span class="line">    <span class="token class-name static-context">Telescope</span><span class="token operator">::</span><span class="token function">tag</span><span class="token punctuation">(</span><span class="token keyword">function</span> <span class="token punctuation">(</span><span class="token class-name type-declaration">IncomingEntry</span> <span class="token variable">$entry</span><span class="token punctuation">)</span> <span class="token punctuation">{</span></span>
<span class="line">        <span class="token keyword">if</span> <span class="token punctuation">(</span><span class="token variable">$entry</span><span class="token operator">-></span><span class="token property">type</span> <span class="token operator">===</span> <span class="token string single-quoted-string">'request'</span><span class="token punctuation">)</span> <span class="token punctuation">{</span></span>
<span class="line">            <span class="token keyword">return</span> <span class="token punctuation">[</span><span class="token string single-quoted-string">'status:'</span><span class="token operator">.</span><span class="token variable">$entry</span><span class="token operator">-></span><span class="token property">content</span><span class="token punctuation">[</span><span class="token string single-quoted-string">'response_status'</span><span class="token punctuation">]</span><span class="token punctuation">]</span><span class="token punctuation">;</span></span>
<span class="line">        <span class="token punctuation">}</span></span>
<span class="line"></span>
<span class="line">        <span class="token keyword">return</span> <span class="token punctuation">[</span><span class="token punctuation">]</span><span class="token punctuation">;</span></span>
<span class="line">    <span class="token punctuation">}</span><span class="token punctuation">)</span><span class="token punctuation">;</span></span>
<span class="line"> <span class="token punctuation">}</span></span>
<span class="line"></span></code></pre>
<div class="line-numbers" aria-hidden="true" style="counter-reset:line-number 0"><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div></div></div><h2 id="可用的监听" tabindex="-1"><a class="header-anchor" href="#可用的监听"><span>可用的监听</span></a></h2>
<p>当在控制台执行命令或处理请求时，<code v-pre>Telescope</code> 监听器会收集应用程序数据。您可以在 config/telescope.php 配置文件中自定义要启用监听项的列表：</p>
<div class="language-php line-numbers-mode" data-highlighter="prismjs" data-ext="php" data-title="php"><pre v-pre class="language-php"><code><span class="line"><span class="token string single-quoted-string">'watchers'</span> <span class="token operator">=></span> <span class="token punctuation">[</span></span>
<span class="line">    <span class="token class-name class-name-fully-qualified static-context">Watchers<span class="token punctuation">\</span>CacheWatcher</span><span class="token operator">::</span><span class="token keyword">class</span> <span class="token operator">=></span> <span class="token constant boolean">true</span><span class="token punctuation">,</span></span>
<span class="line">    <span class="token class-name class-name-fully-qualified static-context">Watchers<span class="token punctuation">\</span>CommandWatcher</span><span class="token operator">::</span><span class="token keyword">class</span> <span class="token operator">=></span> <span class="token constant boolean">true</span><span class="token punctuation">,</span></span>
<span class="line">    <span class="token operator">...</span></span>
<span class="line"><span class="token punctuation">]</span><span class="token punctuation">,</span></span>
<span class="line"></span></code></pre>
<div class="line-numbers" aria-hidden="true" style="counter-reset:line-number 0"><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div></div></div><p>一些监听器还允许您提供其他自定义选项：</p>
<div class="language-php line-numbers-mode" data-highlighter="prismjs" data-ext="php" data-title="php"><pre v-pre class="language-php"><code><span class="line"><span class="token string single-quoted-string">'watchers'</span> <span class="token operator">=></span> <span class="token punctuation">[</span></span>
<span class="line">    <span class="token class-name class-name-fully-qualified static-context">Watchers<span class="token punctuation">\</span>QueryWatcher</span><span class="token operator">::</span><span class="token keyword">class</span> <span class="token operator">=></span> <span class="token punctuation">[</span></span>
<span class="line">        <span class="token string single-quoted-string">'enabled'</span> <span class="token operator">=></span> <span class="token function">env</span><span class="token punctuation">(</span><span class="token string single-quoted-string">'TELESCOPE_QUERY_WATCHER'</span><span class="token punctuation">,</span> <span class="token constant boolean">true</span><span class="token punctuation">)</span><span class="token punctuation">,</span></span>
<span class="line">        <span class="token string single-quoted-string">'slow'</span> <span class="token operator">=></span> <span class="token number">100</span><span class="token punctuation">,</span></span>
<span class="line">    <span class="token punctuation">]</span><span class="token punctuation">,</span></span>
<span class="line">    <span class="token operator">...</span></span>
<span class="line"><span class="token punctuation">]</span><span class="token punctuation">,</span></span>
<span class="line"></span></code></pre>
<div class="line-numbers" aria-hidden="true" style="counter-reset:line-number 0"><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div></div></div><h3 id="缓存监听" tabindex="-1"><a class="header-anchor" href="#缓存监听"><span>缓存监听</span></a></h3>
<p>当缓存键被命中、遗漏、更新和遗忘时，缓存监听器会记录数据。</p>
<h3 id="命令监听" tabindex="-1"><a class="header-anchor" href="#命令监听"><span>命令监听</span></a></h3>
<p>只要执行 Artisan 命令，命令监听器就会记录参数、选项、退出代码和输出。如果您想排除监听器记录的某些命令，您可以在 config/telescope.php 文件的 ignore 选项中指定命令：</p>
<div class="language-php line-numbers-mode" data-highlighter="prismjs" data-ext="php" data-title="php"><pre v-pre class="language-php"><code><span class="line"><span class="token string single-quoted-string">'watchers'</span> <span class="token operator">=></span> <span class="token punctuation">[</span></span>
<span class="line">    <span class="token class-name class-name-fully-qualified static-context">Watchers<span class="token punctuation">\</span>CommandWatcher</span><span class="token operator">::</span><span class="token keyword">class</span> <span class="token operator">=></span> <span class="token punctuation">[</span></span>
<span class="line">        <span class="token string single-quoted-string">'enabled'</span> <span class="token operator">=></span> <span class="token function">env</span><span class="token punctuation">(</span><span class="token string single-quoted-string">'TELESCOPE_COMMAND_WATCHER'</span><span class="token punctuation">,</span> <span class="token constant boolean">true</span><span class="token punctuation">)</span><span class="token punctuation">,</span></span>
<span class="line">        <span class="token string single-quoted-string">'ignore'</span> <span class="token operator">=></span> <span class="token punctuation">[</span><span class="token string single-quoted-string">'key:generate'</span><span class="token punctuation">]</span><span class="token punctuation">,</span></span>
<span class="line">    <span class="token punctuation">]</span><span class="token punctuation">,</span></span>
<span class="line">    <span class="token operator">...</span></span>
<span class="line"><span class="token punctuation">]</span><span class="token punctuation">,</span></span>
<span class="line"></span></code></pre>
<div class="line-numbers" aria-hidden="true" style="counter-reset:line-number 0"><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div></div></div><h3 id="数据监听" tabindex="-1"><a class="header-anchor" href="#数据监听"><span>数据监听</span></a></h3>
<p>数据监听器在 Telescope 中记录并显示您的数据变量。使用 Laravel 时，可以使用全局 dump 函数输出变量。必须在浏览器中打开数据监听器选项卡，才能进行输出变量，否则监听器将忽略此次输出。</p>
<h3 id="事件监听" tabindex="-1"><a class="header-anchor" href="#事件监听"><span>事件监听</span></a></h3>
<p>事件监听器记录应用程序调度的任何事件的有效负载、监听器和广播数据。事件监听器忽略了 Laravel 框架的内部事件。</p>
<h3 id="异常监听" tabindex="-1"><a class="header-anchor" href="#异常监听"><span>异常监听</span></a></h3>
<p>异常监听器记录应用程序引发的任何可报告异常的数据和堆栈跟踪。</p>
<h3 id="gate-监听" tabindex="-1"><a class="header-anchor" href="#gate-监听"><span>Gate 监听</span></a></h3>
<p>Gate 监听器记录您的应用程序的 Gate 和策略检查的数据和结果。如果您希望将某些能力排除在监听器的记录之外，您可以在<code v-pre>config/telescope.php</code> 文件的 <code v-pre>ignore_abilities</code> 选项中指定它们：</p>
<div class="language-php line-numbers-mode" data-highlighter="prismjs" data-ext="php" data-title="php"><pre v-pre class="language-php"><code><span class="line"><span class="token string single-quoted-string">'watchers'</span> <span class="token operator">=></span> <span class="token punctuation">[</span></span>
<span class="line">    <span class="token class-name class-name-fully-qualified static-context">Watchers<span class="token punctuation">\</span>GateWatcher</span><span class="token operator">::</span><span class="token keyword">class</span> <span class="token operator">=></span> <span class="token punctuation">[</span></span>
<span class="line">        <span class="token string single-quoted-string">'enabled'</span> <span class="token operator">=></span> <span class="token function">env</span><span class="token punctuation">(</span><span class="token string single-quoted-string">'TELESCOPE_GATE_WATCHER'</span><span class="token punctuation">,</span> <span class="token constant boolean">true</span><span class="token punctuation">)</span><span class="token punctuation">,</span></span>
<span class="line">        <span class="token string single-quoted-string">'ignore_abilities'</span> <span class="token operator">=></span> <span class="token punctuation">[</span><span class="token string single-quoted-string">'viewNova'</span><span class="token punctuation">]</span><span class="token punctuation">,</span></span>
<span class="line">    <span class="token punctuation">]</span><span class="token punctuation">,</span></span>
<span class="line">    <span class="token operator">...</span></span>
<span class="line"><span class="token punctuation">]</span><span class="token punctuation">,</span></span>
<span class="line"></span></code></pre>
<div class="line-numbers" aria-hidden="true" style="counter-reset:line-number 0"><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div></div></div><h3 id="进程监听" tabindex="-1"><a class="header-anchor" href="#进程监听"><span>进程监听</span></a></h3>
<p>进程监听器记录应用程序分派的任何作业的数据和状态。</p>
<h3 id="日志监听" tabindex="-1"><a class="header-anchor" href="#日志监听"><span>日志监听</span></a></h3>
<p>日志监视器记录应用程序写入的任何日志的日志数据。</p>
<h3 id="邮件监听" tabindex="-1"><a class="header-anchor" href="#邮件监听"><span>邮件监听</span></a></h3>
<p>邮件监视器允许您查看电子邮件的浏览器内预览及其相关数据。您也可以将该电子邮件下载为 <code v-pre>.eml</code> 文件。</p>
<h3 id="模型监听" tabindex="-1"><a class="header-anchor" href="#模型监听"><span>模型监听</span></a></h3>
<p>只要调度了模型的 <code v-pre>create</code>、<code v-pre>updated</code>、<code v-pre>restored</code> 或 <code v-pre>deleted</code> 事件，模型观察器就会记录模型更改。您可以通过监听器的 <code v-pre>events</code> 选项指定应记录哪些模型事件：</p>
<div class="language-php line-numbers-mode" data-highlighter="prismjs" data-ext="php" data-title="php"><pre v-pre class="language-php"><code><span class="line"><span class="token string single-quoted-string">'watchers'</span> <span class="token operator">=></span> <span class="token punctuation">[</span></span>
<span class="line">    <span class="token class-name class-name-fully-qualified static-context">Watchers<span class="token punctuation">\</span>ModelWatcher</span><span class="token operator">::</span><span class="token keyword">class</span> <span class="token operator">=></span> <span class="token punctuation">[</span></span>
<span class="line">        <span class="token string single-quoted-string">'enabled'</span> <span class="token operator">=></span> <span class="token function">env</span><span class="token punctuation">(</span><span class="token string single-quoted-string">'TELESCOPE_MODEL_WATCHER'</span><span class="token punctuation">,</span> <span class="token constant boolean">true</span><span class="token punctuation">)</span><span class="token punctuation">,</span></span>
<span class="line">        <span class="token string single-quoted-string">'events'</span> <span class="token operator">=></span> <span class="token punctuation">[</span><span class="token string single-quoted-string">'eloquent.created*'</span><span class="token punctuation">,</span> <span class="token string single-quoted-string">'eloquent.updated*'</span><span class="token punctuation">]</span><span class="token punctuation">,</span></span>
<span class="line">    <span class="token punctuation">]</span><span class="token punctuation">,</span></span>
<span class="line">    <span class="token operator">...</span></span>
<span class="line"><span class="token punctuation">]</span><span class="token punctuation">,</span></span>
<span class="line"></span></code></pre>
<div class="line-numbers" aria-hidden="true" style="counter-reset:line-number 0"><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div></div></div><h3 id="消息通知监听" tabindex="-1"><a class="header-anchor" href="#消息通知监听"><span>消息通知监听</span></a></h3>
<p>消息通知监听器记录您的应用程序发送的所有通知。如果通知触发了电子邮件并且您启用了邮件监听器，则电子邮件也可以在邮件监视器屏幕上进行预览。</p>
<h3 id="数据查询监听" tabindex="-1"><a class="header-anchor" href="#数据查询监听"><span>数据查询监听</span></a></h3>
<p>数据查询监听器记录应用程序执行的所有查询的原始 SQL、绑定和执行时间。观察者还将任何慢于 100 毫秒的查询标记为 <code v-pre>slow</code>。您可以使用观察者的 <code v-pre>slow</code> 选项自定义慢查询阈值：</p>
<div class="language-php line-numbers-mode" data-highlighter="prismjs" data-ext="php" data-title="php"><pre v-pre class="language-php"><code><span class="line"><span class="token string single-quoted-string">'watchers'</span> <span class="token operator">=></span> <span class="token punctuation">[</span></span>
<span class="line">    <span class="token class-name class-name-fully-qualified static-context">Watchers<span class="token punctuation">\</span>QueryWatcher</span><span class="token operator">::</span><span class="token keyword">class</span> <span class="token operator">=></span> <span class="token punctuation">[</span></span>
<span class="line">        <span class="token string single-quoted-string">'enabled'</span> <span class="token operator">=></span> <span class="token function">env</span><span class="token punctuation">(</span><span class="token string single-quoted-string">'TELESCOPE_QUERY_WATCHER'</span><span class="token punctuation">,</span> <span class="token constant boolean">true</span><span class="token punctuation">)</span><span class="token punctuation">,</span></span>
<span class="line">        <span class="token string single-quoted-string">'slow'</span> <span class="token operator">=></span> <span class="token number">50</span><span class="token punctuation">,</span></span>
<span class="line">    <span class="token punctuation">]</span><span class="token punctuation">,</span></span>
<span class="line">    <span class="token operator">...</span></span>
<span class="line"><span class="token punctuation">]</span><span class="token punctuation">,</span></span>
<span class="line"></span></code></pre>
<div class="line-numbers" aria-hidden="true" style="counter-reset:line-number 0"><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div></div></div><h3 id="redis-监听" tabindex="-1"><a class="header-anchor" href="#redis-监听"><span>Redis 监听</span></a></h3>
<p>必须启用 Redis 事件才能使 Redis 监听器正常运行。您可以通过在 app/Providers/AppServiceProvider.php 文件的 boot 方法中调用 Redis::enableEvents() 来启用 Redis 事件。</p>
<p>Redis 监听器记录您的应用程序执行的所有 Redis 命令。如果您使用 Redis 进行缓存，Redis 监听器也会记录缓存命令。</p>
<h3 id="请求监听" tabindex="-1"><a class="header-anchor" href="#请求监听"><span>请求监听</span></a></h3>
<p>请求监听器记录与应用程序处理的任何请求相关联的请求、标头、会话和响应数据。您可以通过 <code v-pre>size_limit</code> （以 KB 为单位）选项限制响应数据：</p>
<div class="language-php line-numbers-mode" data-highlighter="prismjs" data-ext="php" data-title="php"><pre v-pre class="language-php"><code><span class="line"><span class="token string single-quoted-string">'watchers'</span> <span class="token operator">=></span> <span class="token punctuation">[</span></span>
<span class="line">    <span class="token class-name class-name-fully-qualified static-context">Watchers<span class="token punctuation">\</span>RequestWatcher</span><span class="token operator">::</span><span class="token keyword">class</span> <span class="token operator">=></span> <span class="token punctuation">[</span></span>
<span class="line">        <span class="token string single-quoted-string">'enabled'</span> <span class="token operator">=></span> <span class="token function">env</span><span class="token punctuation">(</span><span class="token string single-quoted-string">'TELESCOPE_REQUEST_WATCHER'</span><span class="token punctuation">,</span> <span class="token constant boolean">true</span><span class="token punctuation">)</span><span class="token punctuation">,</span></span>
<span class="line">        <span class="token string single-quoted-string">'size_limit'</span> <span class="token operator">=></span> <span class="token function">env</span><span class="token punctuation">(</span><span class="token string single-quoted-string">'TELESCOPE_RESPONSE_SIZE_LIMIT'</span><span class="token punctuation">,</span> <span class="token number">64</span><span class="token punctuation">)</span><span class="token punctuation">,</span></span>
<span class="line">    <span class="token punctuation">]</span><span class="token punctuation">,</span></span>
<span class="line">    <span class="token operator">...</span></span>
<span class="line"><span class="token punctuation">]</span><span class="token punctuation">,</span></span>
<span class="line"></span></code></pre>
<div class="line-numbers" aria-hidden="true" style="counter-reset:line-number 0"><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div></div></div><h3 id="schedule-监听" tabindex="-1"><a class="header-anchor" href="#schedule-监听"><span>Schedule 监听</span></a></h3>
<p>Schedule 监听器记录应用程序运行的任何计划任务的命令和输出。</p>
<blockquote>
<p>本译文仅用于学习和交流目的，转载请务必注明文章译者、出处、和本文链接<br>
我们的翻译工作遵照 <a href="https://learnku.com/docs/guide/cc4.0/6589" target="_blank" rel="noopener noreferrer">CC 协议</a>，如果我们的工作有侵犯到您的权益，请及时联系我们。</p>
</blockquote>
<hr>
<blockquote>
<p>原文地址：<a href="https://learnku.com/docs/laravel/6.x/telescope/5193" target="_blank" rel="noopener noreferrer">https://learnku.com/docs/laravel/6.x/tel...</a></p>
<p>译文地址：<a href="https://learnku.com/docs/laravel/6.x/telescope/5193" target="_blank" rel="noopener noreferrer">https://learnku.com/docs/laravel/6.x/tel...</a></p>
</blockquote>
</div></template>


